package gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

public class TelaNovoAtoProcessual extends JDialog implements KeyListener {

	private static final long serialVersionUID = 1L;

	private JPanel contentPane;
	
	private JPanel panelPrincipal;
	private JPanel panelNumeroProcesso;
	private JPanel panelTipoAto;
	private JScrollPane scrollPaneObservacao;

	private JTextField textNumeroProcesso;
	private JComboBox comboBoxTiposAto;
	
	private JTextArea textAreaObservacao;
	
	private JButton botaoNovoTipo;
	private JButton botaoCadastrar;
	private JButton botaoCancelar;

	/**
	 * Create the frame.
	 */
	public TelaNovoAtoProcessual(JFrame pai) {
		super(pai, "Cadastrar Novo Ato Processual");
		this.addKeyListener(this);
		initialize(pai);
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		if(e.getKeyCode()==KeyEvent.VK_ESCAPE)
			TelaNovoAtoProcessual.this.dispose();
	}

	@Override
	public void keyReleased(KeyEvent e) {
	}

	@Override
	public void keyTyped(KeyEvent e) {
	}
	
	private void initialize(final JFrame pai){
		setResizable(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 328);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		panelPrincipal = new JPanel();
		contentPane.add(panelPrincipal, BorderLayout.CENTER);
		
		panelNumeroProcesso = new JPanel();
		panelNumeroProcesso.setBorder(new TitledBorder(null, "", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		
		panelTipoAto = new JPanel();
		panelTipoAto.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JLabel labelObservacao = new JLabel("Observa\u00E7\u00E3o:");
		
		scrollPaneObservacao = new JScrollPane();
		
		botaoCadastrar = new JButton("Cadastrar");
		
		botaoCancelar = new JButton("Cancelar");
		botaoCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TelaNovoAtoProcessual.this.dispose();
			}
		});
		GroupLayout gl_panelPrincipal = new GroupLayout(panelPrincipal);
		gl_panelPrincipal.setHorizontalGroup(
			gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelPrincipal.createSequentialGroup()
					.addGap(6)
					.addGroup(gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panelPrincipal.createSequentialGroup()
							.addComponent(botaoCancelar, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 258, Short.MAX_VALUE)
							.addComponent(botaoCadastrar))
						.addComponent(panelNumeroProcesso, GroupLayout.PREFERRED_SIZE, 422, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_panelPrincipal.createParallelGroup(Alignment.TRAILING, false)
							.addGroup(Alignment.LEADING, gl_panelPrincipal.createSequentialGroup()
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(labelObservacao)
								.addGap(14)
								.addComponent(scrollPaneObservacao))
							.addComponent(panelTipoAto, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 395, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		gl_panelPrincipal.setVerticalGroup(
			gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelPrincipal.createSequentialGroup()
					.addGap(6)
					.addComponent(panelNumeroProcesso, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panelTipoAto, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
						.addComponent(labelObservacao)
						.addComponent(scrollPaneObservacao, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
						.addComponent(botaoCancelar, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(botaoCadastrar, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
					.addContainerGap())
		);
		gl_panelPrincipal.linkSize(SwingConstants.VERTICAL, new Component[] {panelNumeroProcesso, panelTipoAto});
		gl_panelPrincipal.linkSize(SwingConstants.HORIZONTAL, new Component[] {panelNumeroProcesso, panelTipoAto});
		
		textAreaObservacao = new JTextArea();
		scrollPaneObservacao.setViewportView(textAreaObservacao);
		
		JLabel lblTipoDeAto = new JLabel("Tipo de Ato Processual");
		
		comboBoxTiposAto = new JComboBox();
		
		botaoNovoTipo = new JButton("Novo Tipo");
		botaoNovoTipo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TelaNovoTipo novoTipo = new TelaNovoTipo(pai);
				novoTipo.setVisible(true);
			}
		});
		GroupLayout gl_panelTipoAto = new GroupLayout(panelTipoAto);
		gl_panelTipoAto.setHorizontalGroup(
			gl_panelTipoAto.createParallelGroup(Alignment.LEADING)
				.addComponent(lblTipoDeAto)
				.addGroup(Alignment.TRAILING, gl_panelTipoAto.createSequentialGroup()
					.addComponent(comboBoxTiposAto, GroupLayout.PREFERRED_SIZE, 260, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
					.addComponent(botaoNovoTipo))
		);
		gl_panelTipoAto.setVerticalGroup(
			gl_panelTipoAto.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelTipoAto.createSequentialGroup()
					.addComponent(lblTipoDeAto)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panelTipoAto.createParallelGroup(Alignment.LEADING)
						.addComponent(botaoNovoTipo)
						.addComponent(comboBoxTiposAto, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
		);
		panelTipoAto.setLayout(gl_panelTipoAto);
		
		JLabel labelNumeroProcesso = new JLabel("N\u00FAmero do Processo");
		
		textNumeroProcesso = new JTextField();
		textNumeroProcesso.setColumns(10);
		GroupLayout gl_panelNumeroProcesso = new GroupLayout(panelNumeroProcesso);
		gl_panelNumeroProcesso.setHorizontalGroup(
			gl_panelNumeroProcesso.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNumeroProcesso.createSequentialGroup()
					.addGroup(gl_panelNumeroProcesso.createParallelGroup(Alignment.LEADING)
						.addComponent(labelNumeroProcesso)
						.addComponent(textNumeroProcesso, GroupLayout.PREFERRED_SIZE, 260, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(142, Short.MAX_VALUE))
		);
		gl_panelNumeroProcesso.setVerticalGroup(
			gl_panelNumeroProcesso.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNumeroProcesso.createSequentialGroup()
					.addComponent(labelNumeroProcesso)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textNumeroProcesso, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(12, Short.MAX_VALUE))
		);
		panelNumeroProcesso.setLayout(gl_panelNumeroProcesso);
		panelPrincipal.setLayout(gl_panelPrincipal);
	}
}
